Ease code inclusion#3169
Conversation
easier to use than include_file
Preview of modified filesPreview of modified Markdown: |
558fd24 to
8d54540
Compare
ff97459 to
980e3a6
Compare
| return glue.join(line_range) | ||
|
|
||
| @env.macro | ||
| def include_code(filename, start_line=1, end_line=None, indent_level=0, remove_indent=False): |
There was a problem hiding this comment.
Can you add docstring doc to include_file and mention that's it's deprecated/replaced by include_code - so that Copilot won't try to use that
And maybe docstring doc here as well, for the 🤖 to deal with it better 😄
There was a problem hiding this comment.
Done in a9391ca
I also renamed the first argument from filename to file_path to better match the expected value.
be63d97 to
a9391ca
Compare
|
mnocon
left a comment
There was a problem hiding this comment.
Thanks!
Can you please backport this to v4.6? To make sure nothing fails when we cherry-pick from 5.0 to 4.6 with the new approach.
And please share this on Slack with @julitafalcondusza and @dabrt , to build awareness of a more intuitive alternative to include_file
* main.py: Add include_code function * code_samples_usage.php: Update for include_code * convert docs/administration/recent_activity/recent_activity.md * convert docs/api/rest_api/rest_api_usage/rest_requests.md * convert docs/search/search_api.md * convert docs/templating/twig_function_reference/image_twig_functions.md
* main.py: Add include_code function * code_samples_usage.php: Update for include_code * convert docs/administration/recent_activity/recent_activity.md * convert docs/api/rest_api/rest_api_usage/rest_requests.md * convert docs/search/search_api.md * convert docs/templating/twig_function_reference/image_twig_functions.md




Introduce
include_codefunction.include_codehas four optional arguments:start_lineinteger,1by default: the real one!end_linenumber,Noneby defaultindent_levelinteger,0by default: how many times four spaces are added in front of the lines, mainly used for boxes and tabsremove_indentboolean,Falseby default: to remove has much indentation as possiblenew
include_codeVS oldinclude_fileinclude_codedoesn't end with its new line feed whileinclude_filedoes which complicate concatenating slices or inserting hard coded lines like ellipsis commentsinclude_codestarts with the first line real number whileinclude_fileneed to decrease it by oneExamples
docs/search/search_api.mdshows in several places how line feeds are easier to control.docs/api/rest_api/rest_api_usage/rest_requests.mdshows twoindent_levelusage, one as the third argument, one as the only named argument.docs/administration/recent_activity/recent_activity.mdvalidatesremove_indent(used as a named argument)docs/templating/twig_function_reference/image_twig_functions.mdshows that it works with.mdfiles too (it was starting on an empty line)Update
tools/code_samples/code_samples_usage.phpto also reportinclude_codechanges.While on it, also update it to handle named parameters like, for example,
remove_indent=True.This is a manually generate diff:
code_samples_usage.diff.html
It also shows that 5.0 version fails on
remove_indent=TrueI added
code_samples/api/product_catalog/src/Command/ProductCommand.phpfor more test cases.Here is the whole file list I checked for include usage on
5.0andinclude_codebranches to generate the diff:Locally, I tested "removing indents but one" with success:
docs/tmp.yaml
doc.tmp.md
Locally, it works visually on
/en/latest/tmp/and in a terminal withphp tools/code_samples/code_samples_usage.php docs/tmp.yamlChecklist